package com.example.goup17booksmanagement;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.widget.Toast;

public class AlarmReceive extends BroadcastReceiver {
	IntentFilter intentFilter;
	int notificationID = 1;

	@Override
	public void onReceive(Context context, Intent intent) {

		String bookName = intent.getStringExtra(SetSchedule.BOOK_NAME);
		Toast.makeText(context, "wake up -------", Toast.LENGTH_SHORT).show();
		displayNotification(context, bookName);
	}

	@SuppressWarnings("deprecation")
	public void displayNotification(Context context, String bookName) {
		// ---PendingIntent to launch activity if the user selects
		// this notification---
		Intent i = new Intent(context, NotificationView.class);
		i.putExtra("notificationID", notificationID);
		PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, i, 0);
		
		NotificationManager nm = (NotificationManager) context.getSystemService(android.content.Context.NOTIFICATION_SERVICE);
		
		Notification notif = new Notification(R.drawable.book1,
				"Read Book",
				System.currentTimeMillis());
		CharSequence from = "Book Management";
		CharSequence message = "Read book " + bookName;
		notif.setLatestEventInfo(context, from, message, pendingIntent);
		nm.notify(notificationID, notif);
	}
}
